$(document).ready(function () {

    $('#data-wrapper select').select0();

    UE.delEditor('editor');
    UE.getEditor('editor').ready(function () {
        UE.getEditor('editor').setContent($('#data-wrapper [name="content"]').val());
    });

    $('#data-wrapper .btn-4-back').off('click').on('click', function () {
        ajaxSubmitResponseHtm({
            // container: '#pop-wrapper',
            url: 'notice/query.htm',
        });
    });

    $('#data-wrapper .btn-4-choice').off('click').on('click', function () {
        ajaxSubmitResponseHtm({
            container: '#pop-wrapper',
            url: 'notice/choiceBrand.htm',
        });
    });

    $('#data-wrapper .btn-4-save').off('click').on('click', function () {
        var id = $('#data-wrapper input:hidden[name="id"]').val();
        var url = 'notice/add.htm';
        if (id) {
            url = 'notice/modify.htm';
        }
        if ($("#data-wrapper input[name='title']").val() == '') {
            $("#data-wrapper input[name='title']").focus();
            tipData({message: '标题必填', status: 0});
            return;
        }

        if ($("#data-wrapper select[name='type']").val() == '') {
            $("#data-wrapper select[name='type']").focus();
            tipData({message: '文章类别必选', status: 0});
            return;
        }

        var _content = UE.getEditor('editor').getContent();
        $('#data-wrapper [name="content"]').val(_content);
        if ($("#data-wrapper [name='content']").val() == '') {
            $("#data-wrapper [name='content']").focus();
            tipData({message: '内容必填', status: 0});
            return;
        }
        ajaxSubmitResponseJSON({
            url: url,
            method: 'POST',
            data: $('#data-wrapper form').serialize(),
            success: function (data) {
                if (data.status == 0) {
                    tipData({message:data.message, status:0})
                    ajaxSubmitResponseHtm({
                        // container: '#pop-wrapper',
                        url: 'notice/query.htm',
                    });
                }
            }
        });
    });

});